<?php
include ("config.php");

function getRows($tables,$from){
    $query = mysql_query("SELECT $tables FROM `$from` ");
    $rows = array();
    while($row = mysql_fetch_assoc($query)){
        $rows[] = $row;
    }
    return $rows;
}
function getRow($tables,$id,$from){
    $query = mysql_query("SELECT $tables FROM `$from` WHERE id='$id'");
    $rows = array();
    while($row = mysql_fetch_assoc($query)){
        $rows[] = $row;
    }
    return $rows;
}

function addPractices($data){

    $date_start = $data['date_start'];
    $date_end = $data['date_end'];
    $amount = $data['amount'];
    $paid = $data['paid'];
    if($paid == "on"){
        $paid = 1;
    }
    else{
        $paid = 0;
    }
    $duties = $data['duties'];
    $requirements = $data['requirements'];
    foreach($data['tech'] as $key => $value){
        $technology .= $value.", ";
    }
    $company_id = $data['company_id'];
    $company_person =$data['company_person'];
    $date = date("y-m-d");

    $query = "INSERT INTO `practices` (`add_date`,`date_start`,`date_end`,`amount`,`paid`,`duties`,`requirements`,`technology`,`company_id`,`company_person`)
              VALUES
              ('$date','$date_start','$date_end','$amount','$paid','$duties','$requirements','$technology','$company_id','$company_person')";
    mysql_query($query); 
}
function addStudent($data){
    $email = $data['email'];
    $password = md5($data['password']) ;
    $name = $data['s_name'];
    $surname = $data['s_surname'] ;
    $album_nr = $data['s_album'];
    $faculty_id = $data['s_faculty'];
    $specialization_id = $data['s_specialization'];

    $query = "INSERT INTO `user_student` (`email`,`password`,`name`,`surname`,`album_nr`,`faculty_id`,`specialization_id`)
              VALUES ('$email','$password','$name','$surname','$album_nr','$faculty_id','$specialization_id')";

    mysql_query($query);
}
function addCompany($data){
    echo addCompany_person($data);
    $name = $data['c_person_name'];
    $surname = $data['c_person_surname'];
    $email = $data['c_person_email'];
    $query = mysql_query("SELECT id FROM `company_person` WHERE (name ='$name' AND surname ='$surname' AND email ='$email' )");
    
    $row = mysql_fetch_assoc($query);

    $person_id = $row['id'];
    $email = $data['email'];
    $password = md5($data['password']);
    $name = $data['c_name'];
    $address = $data['c_address'];
    $phone = $data['c_phone'];
    $site = $data['c_site'];

    $query = mysql_query("INSERT INTO `user_company` (`email`,`password`,`name`,`address`,`phone`,`site`,`person_id`)
                          VALUES ('$email','$password','$name','$address','$phone','$site','$person_id')");
}
function addCompany_person($data){
    $name = $data['c_person_name'];
    $surname = $data['c_person_surname'];
    $position = $data['c_person_position'];
    $email = $data['c_person_email'];
    $phone = $data['c_person_phone'];

    $query = mysql_query("INSERT INTO `company_person` (`name`,`surname`,`position`,`email`,`phone`)
              VALUES ('$name','$surname','$position','$email','$phone')");
}
?>
